<template>
  <div :style="{ width: width, height: height, background: `url(${url})` }" class="card">
    <div class="title-text">{{ title }}</div>
    <div v-if="recentlyList.length > 0" class="content-list">
      <div v-for="(item, index) in recentlyList.slice(0, 4)" :key="index" class="list-span" @click="handelCollect(item)">
        <span class="iconfont icon-time-line time-class"></span>
        <span class="elliptical-1 collect-time-text" :title="`${item.objectName || item.name}`">{{ item.objectName || item.name }}</span>
      </div>
    </div>
    <div v-if="recentlyList.length === 0" class="content-null">
      <img src="@/assets/img/empty-image.png" />
      <div class="empty-tips mt-4">{{ emptyText }}</div>
    </div>
    <div class="footer-button" @click="handelButton">{{ footerBtnText }}</div>
  </div>
</template>

<script lang="ts" setup>
  import url from '@/assets/img/image39.png'

  export interface ListType {
    id: string
    objectName?: string
    title?: string
    createTime?: string
    favoriteType?: number
    objectId?: string
    userId?: string
  }

  export interface CollectCardType {
    id?: string
    width?: string
    height?: string
    recentlyList?: any[]
    title?: string
    emptyText?: string
    footerBtnText?: string
    go: Function
  }

  let props = withDefaults(defineProps<CollectCardType>(), {
    width: '284px',
    height: '216px',
    title: '最近收藏',
    emptyText: '最近没有收藏哦～',
    footerBtnText: '我的收藏',
    recentlyList: () => []
  })

  let emits = defineEmits(['onClick'])

  const handelButton = () => {
    emits('onClick')
  }

  const handelCollect = (item: any) => {
    props.go(item)
  }
</script>
<style lang="less" scoped>
  .card {
    padding: 0 16px;
    background: var(--primary-cobalt-06, #1868e9);
    border-radius: 10px;

    /* Shadow/M */
    box-shadow: 0 2px 8px 0 rgba(37, 37, 45, 0.14), 0 1px 3px 0 rgba(37, 37, 45, 0.14);
  }

  .title-text {
    padding-top: 12px;
    margin-bottom: 8px;
    color: #fff;
    .font14b();
  }

  .footer-button {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 7px 16px;
    width: 254px;
    height: 36px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid var(--text-text-secondary-3, #415e8c);
    border-radius: 6px;
    box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.04), 0 4px 4px 0 rgba(0, 0, 0, 0.25);
    gap: 6px;
    flex-shrink: 0;
    cursor: pointer;

    &:hover {
      background: rgba(255, 255, 255, 0.2);
      border: 1px solid var(--text-text-secondary-3, #415e8c);
      border-radius: 6px;
      box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.04), 0 4px 4px 0 rgba(0, 0, 0, 0.25);
    }
  }

  .content-null {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 123px;

    .empty-tips {
      font-size: 14px;
      text-align: center;
      color: rgba(255, 255, 255, 0.45);
      font-weight: 400;
      line-height: 22px; /* 157.143% */
    }
  }

  .content-list {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 123px;
    gap: 6px;

    .list-span {
      display: flex;
      gap: 8px;
      align-items: center;
      cursor: pointer;
    }
  }

  .collect-time-text {
    color: rgba(255, 255, 255, 0.8);
    .font14();

    &:hover {
      text-decoration: underline;
      color: #649af0;
    }
  }

  .time-class {
    color: rgba(255, 255, 255, 0.8);
  }
</style>
